<?php
	
require_once("library/consts.php");
require_once("library/functions.php");
	
function initialize($where) {	
	global $consts;
	session_start();
	
	if (!session_is_registered('initialized')){
		header("Location: init.php");
	};
	
	mysql_connect($consts['db_servername'], $consts['db_username'], $consts['db_password']) or die('can not connect database');
	mysql_select_db($consts['db_name']);
	
	if ($where!=''){$_SESSION['where']=$where;}
	
	switch ($_SESSION['where']) {
		case 'admin': {
			if (!check_permission('admin')){header("Location: main.php");}
			$_SESSION['view'] = (isset($_GET['view'])) ? $_GET['view'] : 'entries';
			$_SESSION['page'] = (isset($_GET['page'])) ? $_GET['page'] : 1;
			$_SESSION['id']   = (isset($_GET['id']))   ? $_GET['id']   : 0;
			break;}
		case 'main': {
			$_SESSION['view'] = (isset($_GET['view'])) ? $_GET['view'] : 'home';
			$_SESSION['page'] = (isset($_GET['page'])) ? $_GET['page'] : 1;
			$_SESSION['id']   = (isset($_GET['id']))   ? $_GET['id']   : 0;
		}
	}			
}

function get_message() {
$code = <<<HTML
	<script>const MESSAGE = '%s'</script>
HTML;
	printf($code,$_SESSION['message']);
	$_SESSION['message'] = '';
}

?>